﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL;
using MyBind;

public partial class Communicate_BBSSecAddMst : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request["secId"] != null)
            {
                Session["secId"] = Request["secId"].ToString();
            }
            bind();
        }
    }

    //初始化
    public void bind()
    {
        if (Session["secId"] != null)
            {
                string secId=Session["secId"].ToString();
                DAL.bbsSection dalSec = new bbsSection();
                this.lblSec.Text+=dalSec.GetName("id=" + secId);
                this.txtOtherMan.Value=getSecMst(secId);
            }
    }

    //获得版主信息
    protected string getSecMst(string secId)
    {
        string retStr = "";
        DAL.bbsSecMaster master = new bbsSecMaster();
        DataTable dt = master.GetDetailedList("secId=" + secId).Tables[0];
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                retStr += dt.Rows[i]["name"].ToString() + ";";
            }
        }
        else
        {
            retStr = "[暂无]";
        }
        return retStr;
    }

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if(Session["secId"]!=null)
        {
            if(this.txtOtherMan.Value.Trim().Equals(""))
            {
                WriteScript.Mesg(Response, "请选择担任版主的人员");
            }else{
                string secId=Session["secId"].ToString();
                string mst=this.txtOtherMan.Value.Trim();


                string[] mstList = mst.Split(new char[] { ';',' '});
                Sqlselete s = new Sqlselete();
                DAL.bbsSecMaster dalSM = new bbsSecMaster();
                Model.bbsSecMaster mdlSM = new Model.bbsSecMaster();
                int uid = 0;
                bool rs = true;
                for (int i = 0; i < mstList.Length; i++)
                {

                    if (mstList[i] == null || mstList[i].Trim().Equals(""))
                    {
                        //WriteScript.Mesg(Response, "没有检索到数据！");
                    }
                    else
                    {
                        //根据员工名查询id
                        string queryStr=s.SelectEmpByName(mstList[i]);
                        if(!queryStr.Equals(""))
                        {
                            uid=int.Parse(queryStr);
                        }
                        mdlSM.secId = int.Parse(secId);
                        mdlSM.userId = uid;
                        if (dalSM.Add(mdlSM) <= 1) { rs = false; }
                    }
                }
                if (rs)
                {
                    WriteScript.Mesg(Response, "保存成功");
                    WriteScript.ChangeLoca(Response, "BBSSecList.aspx");
                }
            }
        }
    }
    protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("BBSSecList.aspx");
    }
}
